import "./index.css";
import { useState } from "react";

export default function AddTodo(props) {
  const [todoName,setTodoName] = useState("");
  const handleChang = (e) => {
    setTodoName(e.target.value);
  };
  const  hanlekeyup = (e) => {
    if(e.keyCode !==13)return;
    if(!todoName)return;

    props.AddTodo(todoName);
    setTodoName("");

  }

  return (
    <div className="todo-header">
      <input type="text" placeholder="请输入你的任务名称，按回车键确认"
      onChange={handleChang}
      onKeyUp={handleKeyUp}
      value={todoName}
      
      />
    </div>
  );
}
